<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>

<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <title>Code Repository - Home</title>
  <link rel="stylesheet" href="../default.css" />
</head>
<%
UserService userSvc = UserServiceFactory.getUserService();
User currentUser = userSvc.getCurrentUser();
String userName = "";
if (currentUser != null)
{
	userName = currentUser.getNickname();
}
else
{
	String loginUrl = userSvc.createLoginURL("../index.action");
	response.sendRedirect(loginUrl);
}
String logoutUrl = userSvc.createLogoutURL("../index.action");
%>
<body>

    <div id="main">
      <div id="content">
        <div id="login">
          <div id="login-left">Welcome <%= userName %></div>
          <div id="login-right"><a href="<%= logoutUrl%>">Logout</a></div>
        </div>
        <div id="block">
          <h1>Code Snippet Repository</h1>
          <h3>Home</h3>
        </div>
        <div id="strip">All Publicly Viewable Code Snippets</div>
        <div id="block">
          <div id="codesnippet-block"></div>
          <s:if test="allPublicViewableCodeSnippetsEmpty">
            <div id="codesnippet-block">
              There is no public viewable code snippet available...
            </div>
          </s:if>
          <s:else>
            <div id="codesnippet-block">
              <div id="codesnippet-subblock1">
                <b>Date</b>
              </div>
              <div id="codesnippet-subblock2">
                <b>Subject</b>
              </div>
              <div id="codesnippet-subblock3">
                <b>Author</b>
              </div>	  	      
            </div>
	  	    <s:iterator value="allPublicViewableCodeSnippets">
              <div id="codesnippet-block">
                <div id="codesnippet-subblock1">
                  <s:property value="submissionTime"/>
                </div>
                <div id="codesnippet-subblock2">
                  <a href="<s:property value='codeSnippetUrl'/>"><s:property value="subject"/></a>
                </div>
                <div id="codesnippet-subblock3">
                  <s:property value="author"/>
                </div>	  	      
              </div>
            </s:iterator>
          </s:else>
          <div id="codesnippet-block"></div>
          <div id="codesnippet-block">
             <a href="./RetrievePublicViewableCodeSnippets.action?count=1000">
             View All Public Viewable Code Snippets
             </a>
          </div>
          <div id="codesnippet-block"></div>
        </div>
        <div id="strip">Code Snippets Contributed by You</div>
        <div id="block">
          <div id="codesnippet-block"></div>
          <s:if test="currentuserCodeSnippetEmpty">
            <div id="codesnippet-block">
              You have not submitted any code snippets...
            </div>
            <div id="codesnippet-block"></div>
          </s:if>
          <s:else>
            <div id="codesnippet-block">
              <div id="codesnippet-subblock1">
                <b>Date</b>
              </div>
              <div id="codesnippet-subblock2">
                <b>Subject</b>
              </div>
              <div id="codesnippet-subblock3">
                <b>Author</b>
              </div>	  	      
            </div>
            <s:iterator value="currentUserCodeSnippets">
              <div id="codesnippet-block">
                <div id="codesnippet-subblock1">
                  <s:property value="submissionTime"/>
                </div>
                <div id="codesnippet-subblock2">
                  <a href="<s:property value='codeSnippetUrl'/>"><s:property value="subject"/></a>
                </div>
                <div id="codesnippet-subblock3">
                  <s:property value="author"/>
                </div>	  	      
              </div>
            </s:iterator>
          </s:else>
          <div id="codesnippet-block"></div>
          <div id="codesnippet-block">
             <a href="./SaveCodeSnippet.action">
               Add Code Snippet
             </a>&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp; 
             <a href="./RetrieveUserOwnCodeSnippets.action?count=1000">
               View User's Own Code Snippets
             </a>
          </div>
          <div id="codesnippet-block"></div>
        </div>
        <div id="strip"></div>
        <div id="codesnippet-block">
          <div id="codesnippet-block2">
            <a href="AboutThisApp.action">About This App &amp; Privacy Notice</a>
          </div>
        </div>
      </div>
    </div>
</body>
</html>